package cn.songhaiqing.walle.service;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;


import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import cn.songhaiqing.walle.bean.MyApp;

public class NotificationAccessbilityService extends AccessibilityService {
    public static final String FROM_APPLICATION_CONTENT = "FROM_APPLICATION_CONTENT";
    public static final String FROM_WHICH_APPLICATION = "FROM_WHICH_APPLICATION";
    public static final String NOTIFYCATION_ACTION = "NOTIFYCATION_ACTION";
    public static final String PACKAGE_FACEBOOK = "com.facebook.katana";
    public static final String PACKAGE_GMAIL = "com.google.android.gm";
    public static final String PACKAGE_INSTAGRAM = "com.instagram.android";
    public static final String PACKAGE_KAKAOTALK = "com.kakao.talk";
    public static final String PACKAGE_LINE = "jp.naver.line.android";
    public static final String PACKAGE_LINKEDIN = "com.linkedin.android";
    public static final String PACKAGE_MESSENGER = "com.facebook.orca";
    public static final String PACKAGE_QQ = "com.tencent.mobileqq";
    public static final String PACKAGE_SKYPE = "com.skype.raider";
    public static final String PACKAGE_TWITTER = "com.twitter.android";
    public static final String PACKAGE_VIBER = "com.viber.voip";
    public static final String PACKAGE_VKONTAKTE = "com.vkontakte.android";
    public static final String PACKAGE_WECHAT = "com.tencent.mm";
    public static final String PACKAGE_WHATSUP = "com.whatsapp";
    public static final String TAG = "AccessbilityService";
    private Timer delayTimer;
    private AccessibilityServiceInfo info;

    public void onAccessibilityEvent(AccessibilityEvent event) {
        Log.d(TAG, "onAccessibilityEvent");
        List<CharSequence> list = event.getText();
        if (list != null) {
            for (CharSequence c : list) {
                String content = c.toString();
                String packageName = event.getPackageName().toString();
                if (packageName != null && !"".equals(packageName) && c != null && !c.equals("") && !MyApp.getIntance().isSending()) {
                    Intent intent = new Intent(NOTIFYCATION_ACTION);
                    intent.putExtra(FROM_WHICH_APPLICATION, packageName);
                    intent.putExtra(FROM_APPLICATION_CONTENT, content);
                    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
                    MyApp.getIntance().setIsSending(true);
                    startDelayTimer();
                }
            }
        }
    }

    public void onDestroy() {
        super.onDestroy();
    }

    public void onCreate() {
        super.onCreate();
    }

    private void startDelayTimer() {
        if (this.delayTimer == null) {
            this.delayTimer = new Timer();
        }
        this.delayTimer.schedule(new TimerTask() {
            /* class com.gzgamut.smart_movement.service.NotificationAccessbilityService.AnonymousClass1 */

            public void run() {
                MyApp.getIntance().setIsSending(false);
                //TimerHelper.cancelTimer(NotificationAccessbilityService.this.delayTimer);
                NotificationAccessbilityService.this.delayTimer = null;
            }
        }, 3000);
    }

    public void onInterrupt() {
        Log.d(TAG, "onInterrupt");
    }

    /* access modifiers changed from: protected */
    public void onServiceConnected() {
        Log.d(TAG, "onServiceConnected");
        this.info = new AccessibilityServiceInfo();
        this.info.feedbackType = -1;
        this.info.eventTypes = 64;
        AccessibilityServiceInfo accessibilityServiceInfo = this.info;
        accessibilityServiceInfo.packageNames = new String[]{"com.tencent.mobileqq", "com.tencent.mm", PACKAGE_FACEBOOK, PACKAGE_TWITTER, PACKAGE_GMAIL, PACKAGE_WHATSUP};
        this.info.notificationTimeout = 100;
        setServiceInfo(this.info);
    }
}
